/**
 * 
 */
package com.yuanzi.base.util;

import java.util.regex.Pattern;

/**
 * 正则表达式工具类
 * @author weiyx
 * @date 2017年7月3日
 */
public class RegularUtils {
	//电话正则
	public static final String regex_phone = "^((1[3,5,8,9][0-9])|(14[5,7])|(17[0,6,7,8]))\\d{8}$";
	//邮箱正则
    public static final String regex_email = "^([a-z0-9A-Z]+[-_|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
	
    /**
	 * 验证当前用户是邮箱还是手机号
	 * @author weiyx
	 * @param userName 用户名
	 * @date 2017-06-09
	 * @return 0 手机   1 邮箱  -1 错误
	 */
	public static int verifyPhoneOrEmail(String userName){
		
	    if(Pattern.matches(regex_phone, userName)){
	    	return 0;
	    }else if(Pattern.matches(regex_email, userName)){
	    	return 1;
	    }
		return -1;
	}
	
	/**
	 * 验证当前手机号符不符合规范
	 * @param phone
	 * @return
	 */
	public static int verifyPhone(String phone) {
		if(Pattern.matches(regex_phone, phone)){
	    		return 1;
		}
		return 0;
	}
	
	/**
	 * 验证当前邮箱符不符合规范
	 * @param email
	 * @return
	 */
	public static int verifyEmail(String email) {
		if(Pattern.matches(regex_email, email)){
	    		return 1;
		}
		return 0;
	}
}
